********************************************************************************
*     REPLICATION
*     Conflict Abroad and Political Trust at Home: Evidence from a Natural Experiment
*	  Klymak, M., & Vlandas, T. 
********************************************************************************

      version 18
      clear all
      set more off
      use "data.dta", clear
      set scheme s1manual
	 
********************************************************************************
*   DATA PREPARATION
********************************************************************************

      g d10=1 if distance_invasion<=10
      replace d10=0 if distance_invasion<0
      label var d10 "10 days"

      g d14=1 if distance_invasion<=14
      replace d14=0 if distance_invasion<0
      label var d14 "14 days"

      g d21=1 if distance_invasion<=21
      replace d21=0 if distance_invasion<0
      label var d21 "21 days"

      g d28=1 if distance_invasion<=28
      replace d28=0 if distance_invasion<0
      label var d28 "28 days"

      g d31=1 if distance_invasion<=31
      replace d31=0 if distance_invasion<0
      label var d31 "31 days"

      g d40=1 if distance_invasion<=40
      replace d40=0 if distance_invasion<0
      label var d40 "40 days"

      g d50=1 if distance_invasion<=50
      replace d50=0 if distance_invasion<0
      label var d50 "50 days"

      g d60=1 if distance_invasion<=60
      replace d60=0 if distance_invasion<0
      label var d60 "60 days"

	  
********************************************************************************
*   FIGURE 1
********************************************************************************

      local control_vars education age married female ///
	  difficultonincome _Isourceinc_* _Iid_* 

      estimates drop _all

      foreach var of varlist trustpolitician trstprt trstep trustparl {

      quietly: ebalance d10 `control_vars' if distance_invasion<=10 , tar(2) basewt(dweight) 
      eststo d10: quietly reg `var' d10 `control_vars' [pweigh=_webal] if distance_invasion<=10, vce(robust)
      margins, dydx(d10)
      est store d10

      quietly: ebalance d14 `control_vars' if distance_invasion<=14 , tar(2) basewt(dweight) 
      eststo d14: quietly reg `var' d14 `control_vars' [pweigh=_webal] if distance_invasion<=14, vce(robust)
      margins, dydx(d14)
      est store d14

      quietly: ebalance d21 `control_vars' if distance_invasion<=21, tar(2) basewt(dweight) 
      eststo d21: quietly reg `var' d21 `control_vars' [pweigh=_webal] if distance_invasion<=21, vce(robust)
      margins, dydx(d21)
      est store d21

      quietly: ebalance d28 `control_vars' if distance_invasion<=28, tar(2) basewt(dweight) 
      eststo d28: quietly reg `var' d28 `control_vars' [pweigh=_webal] if distance_invasion<=28, vce(robust)
      margins, dydx(d28)
      est store d28

      quietly: ebalance d31 `control_vars' if distance_invasion<=31, tar(2) basewt(dweight) 
      eststo d31: quietly reg `var' d31 `control_vars' [pweigh=_webal] if distance_invasion<=31, vce(robust)
      margins, dydx(d31)
      est store d31

      quietly: ebalance d40 `control_vars' if distance_invasion<=40, tar(2) basewt(dweight) 
      eststo d40: quietly reg `var' d40 `control_vars' [pweigh=_webal] if distance_invasion<=40, vce(robust)
      margins, dydx(d40)
      est store d40

      quietly: ebalance d50 `control_vars' if distance_invasion<=50, tar(2) basewt(dweight) 
      eststo d50: quietly reg `var' d50 `control_vars' [pweigh=_webal] if distance_invasion<=50, vce(robust)
      margins, dydx(d50)
      est store d50

      eststo d60: quietly ebalance d60 `control_vars' if distance_invasion<=60, tar(2) basewt(dweight) 
      eststo d60: quietly reg `var' d60 `control_vars' [pweigh=_webal] if distance_invasion<=60, vce(robust)
      margins, dydx(d60)
      est store d60 
  
      coefplot d10 d14 d21 d28 d31 d40 d50 d60, /// 
      drop(_cons) keep(d10 d14 d21 d28 d31 d40 d50 d60) ///
      yline(0, lcolor(gs8)) msymbol(c) levels(90) ///
      vertical ciopts(recast(. rcap)) ///
      lwidth(thick) legend(off) msize(medlarge) xlabel(, labsize(medium)) ///
      pstyle(p1) color(black%100) graphregion(margin(l-5)) ///
      offset(+.025) coeflabels(d10="10 days" d14="14 days" d21="21 days" ///
      d28="28 days" d31="31 days" d40="40 days" d50="50 days" d60="60 days") ///
      ylabel(, labsize(medium)) ytitle("") xtitle("", size(medium)) name(z, replace)    

      graph export coefplt_`var'.pdf, as(pdf) replace
}




********************************************************************************
*   TABLE 1
********************************************************************************	  
	  
      keep if  distance_invasion<=14

      * Trust in Politicians
      eststo m1: reg trustpolitician war, vce(robust)
      quietly estadd local countryfe "No", replace
      quietly estadd local controls "No", replace      
      estadd ysumm, replace

      ebalance war _Iid_*, tar(2) basewt(dweight)
      eststo m2: reg trustpolitician war _Iid_* [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "No", replace     
      estadd ysumm, replace

      ebalance war `control_vars', tar(2) basewt(dweight)
      eststo m3: reg trustpolitician war `control_vars' [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "Yes", replace
      estadd ysumm, replace

      * Trust in Political Parties
      eststo m4: reg trstprt war, vce(robust)
      quietly estadd local countryfe "No", replace
      quietly estadd local controls "No", replace
      estadd ysumm, replace

      ebalance war _Iid_*, tar(2) basewt(dweight)
      eststo m5: reg trstprt war _Iid_* [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "No", replace
      estadd ysumm, replace

      ebalance war `control_vars', tar(2) basewt(dweight)
      eststo m6: reg trstprt war `control_vars' [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "Yes", replace
      estadd ysumm, replace

      * Trust in the EP
      eststo m7: reg trstep war, vce(robust)
      quietly estadd local countryfe "No", replace
      quietly estadd local controls "No", replace
      estadd ysumm, replace

      ebalance war _Iid_*, tar(2) basewt(dweight)
      eststo m8: reg trstep war _Iid_* [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "No", replace
      estadd ysumm, replace

      ebalance war `control_vars', tar(2) basewt(dweight)
      eststo m9: reg trstep war `control_vars' [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "Yes", replace
      estadd ysumm, replace

      * Trust in Parliament
      eststo m10: reg trustparl war, vce(robust)
      quietly estadd local countryfe "No", replace
      quietly estadd local controls "No", replace
      estadd ysumm, replace

      ebalance war _Iid_*, tar(2) basewt(dweight)
      eststo m11: reg trustparl war _Iid_* [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "No", replace
      estadd ysumm, replace

      ebalance war `control_vars', tar(2) basewt(dweight)
      eststo m12: reg trustparl war `control_vars' [pweight=_webal], vce(robust)
      quietly estadd local countryfe "Yes", replace
      quietly estadd local controls "Yes", replace
      estadd ysumm, replace

      esttab m1 m2 m3 m4 m5 m6 using "table_1.tex", replace ///
      prehead("\begin{table}[htbp]\centering \begin{threeparttable}  \caption{The effect of the invasion on trust.}\label{table1}  \begin{tabular}{l*{6}{c}} \midrule  \\[2ex]") ///
      label se keep(war) star(* 0.10 ** 0.05 *** 0.01) ///
      fragment mtitles("" "" "" "" "" "" "") ///
      mgroups("Trust in politicians" "Trust in parties", pattern(1 0 0 1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
      stats(N r2 ymean, labels("N" "R2" "Mean Dep. var."))


      esttab m7 m8 m9 m10 m11 m12 using "table_1.tex", ///
      prehead("\multicolumn{1}{c}{} \\ \\[-2ex] \midrule") ///
      label se keep(war) star(* 0.10 ** 0.05 *** 0.01) ///
      fragment append mtitles("" "" "" "" "" "" "") ///
      mgroups("Trust in the EP" "Trust in parliament", pattern(1 0 0 1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) erepeat(\cmidrule(lr){@span})) ///
      stats(countryfe controls N r2 ymean, labels("Country FE" "Controls" "N" "R2" "Mean Dep. var.")) ///
      prefoot("\midrule") ///
      postfoot("\bottomrule \end{tabular} \begin{tablenotes} \item \small Note: We use 14 days bandwidth in all specifications. We apply entropy balancing for the control group in regressions presented in columns (2), (3), (5) and (6). Specifications (2), (3), (5) and (6) include country fixed effects, while we also apply the full set of controls in specifications (3) and (6). Control variables include age, gender, education, marital status, income difficulties and source of income. Robust standard errors are adjusted at the individual level. Coefficients that are significantly different from zero are denoted by the following system: $\sym{*}\ p<0.10$; $\sym{**}\ p<0.05$; $\sym{***}\ p<0.01$. Full results are presented in tables B.1 and B.2 in the appendix. \end{tablenotes} \end{threeparttable} \end{table}")
